<template>
	<view class="page">
		<view class="header">
			<image src="../../../static/me/integral/my_record.png"></image>
			<view class="">
				{{study_time}}
			</view>
		</view>
		<view class="aside">
			<view class="section" v-for="item in list" :key="item.id">
				<view class="left"><span>{{item.count}}</span>时</view>
				<view class="right">
					<view>开始：{{item.start_time}}</view>
					<view>结束：{{item.end_time}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getStudyList, getMyStudyTime} from '../../../network/me.js'
	export default {
		data() {
			return {
				study_time: 0,
				list: []
			};
		},
		onLoad() {
			// this.init()
			this.time()
		},
		methods: {
			async time() {
				const result = await getMyStudyTime(2)
				if (!result.flag) return
				this.study_time = result.study_time
			},
			
			async init() {
				const result = await getStudyList(2)
				
				console.log(result)
				if (!result.flag) return
				this.list = result.data.map(item => {
					
					item.count = this.countTime(item.start_time, item.end_time);
					return item
				})
			},
			
			countTime(start, end) {
				let time = new Date(end).getTime() - new Date(start).getTime()
				return Math.round(time / 60000) 
			}
		}
	}
</script>

<style lang="scss">
.page {
	background-color: #F2F2F2;
	.header {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin: 10px;
		padding: 15px 0;
		background-color: #1CBAB6;
		border-radius: 5px;
		color: white;
		font-size: 20px;
		image {
			width: 50px;
			height: 50px;
		}
	}
	
	.aside {
		margin: 10px;
		.section {
			display: flex;
			background-color: white;
			padding: 10px 0;
			align-items: center;
			border-radius: 2px;
			margin: 8px 0;
			box-shadow: 0 0 2px #CCCCCC;
			.left {
				width: 70px;
				color: #1CBAB6;
				text-align: center;
				border-right: 1px dotted #F2F2F2;
				font-size: 14px;
				span {
					font-size: 18px;
				}
			}
			.right {
				flex: 1;
				padding-left: 15px;
			}
		}
	}
	
}
</style>
